package com.bkgy.controller.processParam.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.controller.processParam.dto.ProcessParamDto;
import com.bkgy.controller.processParam.entity.ProcessParamEntity;
import com.bkgy.controller.processParam.mapper.ProcessParamMapper;
import com.bkgy.controller.processParam.service.ProcessParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class ProcessParamServiceImpl extends ServiceImpl<ProcessParamMapper, ProcessParamEntity> implements ProcessParamService {

    @Autowired
    private ProcessParamMapper processParamMapper;

    @Override
    public ProcessParamDto fetchData() {
        List<ProcessParamEntity> processParamEntities = processParamMapper.selectLastFive();
        List<ProcessParamDto.strength> strengths = new ArrayList<>();
        processParamEntities.forEach(entity -> {
            ProcessParamDto.strength strength = new ProcessParamDto.strength();
            strength.setEntId(entity.getEntId());
            strength.setTensileStrength(entity.getTensileStrength());
            strength.setYieldStrength(entity.getYieldStrength());
            strengths.add(strength);
        });
        return getDto(strengths, processParamEntities);
    }

    private ProcessParamDto getDto(List<ProcessParamDto.strength> strengths, List<ProcessParamEntity> processParamEntities) {
        ProcessParamDto processParamDto = new ProcessParamDto();
        processParamDto.setStrengths(strengths);
        processParamDto.setRoughnessLower(processParamEntities.get(0).getRoughnessLower());
        processParamDto.setRoughnessUpper(processParamEntities.get(0).getRoughnessUpper());
        processParamDto.setWidthLower(processParamEntities.get(0).getWidthLower());
        processParamDto.setWidthUpper(processParamEntities.get(0).getWidthUpper());
        processParamDto.setThicknessUpper(processParamEntities.get(0).getThicknessUpper());
        processParamDto.setThicknessLower(processParamEntities.get(0).getThicknessLower());
        processParamDto.setZincLower(processParamEntities.get(0).getZincLower());
        processParamDto.setZincUpper(processParamEntities.get(0).getZincUpper());
        return processParamDto;
    }


}
